package com.twu.biblioteca;

import java.util.ArrayList;
import com.twu.biblioteca.*;

public class AllBooks {

    ArrayList <Book>bookList = new ArrayList<Book>();


    public ArrayList<Book> getBookList(){

        return bookList;
    }

    public void addBooks(Book obj)
    {
        bookList.add(obj);

    }

    public String displayAll(){
        StringBuilder builder = new StringBuilder();
        for(Book book: this.bookList)
        {
            builder.append(book.accessionNumber+"\t");
            builder.append(book.bookName+ "\t\t");
            builder.append(book.author+ "\t");
            builder.append(book.isbn + "\t");
            builder.append(book.availability+ "\n");
        }
        return builder.toString();

    }

    public String findByAccessionNumber(String accNo, int choice){

        Book book1=null;
        String s1;
        for(Book book: this.bookList){

            if( book.accessionNumber.compareTo(accNo) == 0 ){
                book1=book;
                break;
            }
        }

        if(book1!=null ) {

            if(choice==1)
            s1=book1.bookIssue();
            else
            if(choice==2)
            s1=book1.bookReturn();
            else
            s1=null;
        }
        else
            s1="Enter the correct accession number";
        return s1;

    }

}
